# @Time: 2021/8/25
# @Dev: TJ


def xpath_string(html, xpath: str, scrapy: bool = False):
    """
    string() 语法
    :param html: etree.HTML() 对象
    :param xpath: xpath 语法
    :param scrapy: 是否为 scrapy 的依赖库
    :return: 返回可视化的内容
    """

    if scrapy:
        xpath_result = html.xpath(f'string(normalize-space({xpath}))').get()
    else:
        xpath_result = html.xpath(f'string(normalize-space({xpath}))')

    xpath_result = str(xpath_result).strip()
    xpath_result = ' '.join(str(xpath_result).split())
    return xpath_result
